package pers.cjr.demo.model.entity;


import io.swagger.annotations.ApiModel;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.Index;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotBlank;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

@EqualsAndHashCode(callSuper = true)
@Data
@Entity
@Table(
        name = "jpa_user",
        indexes = {     //组合索引
                @Index(name = "idx_name_sex", columnList = "name"),
                @Index(name = "idx_name_sex", columnList = "sex"),
        },
        uniqueConstraints = @UniqueConstraint(      //唯一索引
                name = "uk_name_age", columnNames = {"name", "age"}
        )
)
@ApiModel("测试的用户，专门给JPA测试下用，无实际业务可忽略")
@EntityListeners(AuditingEntityListener.class)
public class JpaUser extends JpaBaseModel {

    @Column(name = "name", columnDefinition = "varchar(255) not null COMMENT '名称'")
    @NotBlank
    private String name;

    @Column(name = "sex", columnDefinition = "int(1) default '0'COMMENT '性别'")
    private Integer sex;

    @Column(name = "age", columnDefinition = "int(3) default '0'COMMENT '年龄'")
    private Integer age;

}